package com.ideal.manage.esms.controller.alarm;

import com.ideal.manage.esms.bean.DTO.PageDto;
import com.ideal.manage.esms.bean.alarm.Alarm;
import com.ideal.manage.esms.bean.alarm.Threshold;
import com.ideal.manage.esms.service.alarm.AlarmService;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("alarm")
public class AlarmController {

    @Resource
    private AlarmService alarmService;

    /**
     * 报警列表请求
     * @param model
     */
    @RequestMapping("alarm_list")
    public void alarmList(Model model){

    }

    /**
     * 警告列表请求
     * @param pageNum
     * @param request
     * @return
     */
    @RequestMapping("alarm_data")
    @ResponseBody
    public PageDto alarmData(int pageNum, HttpServletRequest request){
        List<Alarm> alarms = new ArrayList<>();

        Alarm alarm1 = new Alarm();
        alarm1.setContent("单体压差过大一级");
        alarm1.setName("1#电池包");
        alarm1.setSource("BMS");
        alarm1.setGrade("一级");
        alarm1.setTreatmentSuggestion("马上去现场");
        alarm1.setStatus(1L);
        alarm1.setStartTime(new Date());
        alarm1.setEndTime(new Date());
        alarms.add(alarm1);

        Alarm alarm2 = new Alarm();
        alarm2.setContent("模组过热");
        alarm2.setName("1#电池包5#模组");
        alarm2.setSource("BMS");
        alarm2.setGrade("二级");
        alarm2.setTreatmentSuggestion("未确认");
        alarm2.setStartTime(new Date());
        alarm2.setEndTime(new Date());
        alarms.add(alarm2);

        PageDto pageDto = new PageDto();
        pageDto.setTotal(2L);
        pageDto.setRows(alarms);

        return pageDto;
    }
    @RequestMapping("alarm_today")
    @ResponseBody
    public PageDto alarmDataToday(int pageNum, HttpServletRequest request){
        List<Alarm> alarms = new ArrayList<>();

        Alarm alarm1 = new Alarm();
        alarm1.setContent("单体压差过大一级");
        alarm1.setName("1#电池包");
        alarm1.setSource("BMS");
        alarm1.setGrade("一级");
        alarm1.setTreatmentSuggestion("马上去现场");
        alarm1.setStartTime(new Date());
        alarm1.setEndTime(new Date());
        alarms.add(alarm1);

        Alarm alarm2 = new Alarm();
        alarm2.setContent("模组过热");
        alarm2.setName("1#电池包5#模组");
        alarm2.setSource("BMS");
        alarm2.setGrade("二级");
        alarm2.setTreatmentSuggestion("未确认");
        alarm2.setStartTime(new Date());
        alarm2.setEndTime(new Date());
        alarms.add(alarm2);

        Alarm alarm3 = new Alarm();
        alarm3.setContent("模组过热");
        alarm3.setName("1#电池包5#模组");
        alarm3.setSource("BMS");
        alarm3.setGrade("二级");
        alarm3.setTreatmentSuggestion("未确认");
        alarm3.setStartTime(new Date());
        alarm3.setEndTime(new Date());
        alarms.add(alarm3);

        PageDto pageDto = new PageDto();
        pageDto.setTotal(3L);
        pageDto.setRows(alarms);

        return pageDto;
    }
    /**
     * 事件记录详细
     * @param id
     * @param model
     */
    @RequestMapping("event_detail")
    public void eventDetail(Model model,
                         @RequestParam(value = "id", required = false) Long id){

    }
}
